package com.ccs.testcase;

import org.junit.BeforeClass;
import org.junit.FixMethodOrder;
import org.junit.Test;
import org.junit.runners.MethodSorters;
import org.openqa.selenium.WebDriver;

import com.ccs.functions.Login;
import com.ccs.functions.Logout;
import com.ccs.functions.Webdriver;
import com.ccs.transmittal.Admin_Create_Transmittal_List;
import com.ccs.transmittal.Admin_Transmittal_List;
import com.ccs.transmittal.Misc_Transmittal;
import com.ccs.transmittal.WebApp_Transmittal;


@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class Transmittal_ToWebApp {

	private static WebDriver driver;
	public static String transmittal_number, availment_date;
	public static double transmittal_amount;
	public static String inVisitNo[], outVisitNo[];
	public static double hb_inpatient_amount, hb_outpatient_amount, pf_inpatient_amount, pf_outpatient_amount;
	public static String window_handle;
	
	static
	Webdriver d = new Webdriver();
	Login in = new Login();
	Logout out = new Logout();
	Misc_Transmittal m = new Misc_Transmittal();
	Admin_Transmittal_List atl = new Admin_Transmittal_List();
	Admin_Create_Transmittal_List actl = new Admin_Create_Transmittal_List();
	WebApp_Transmittal wat = new WebApp_Transmittal();
	
	@BeforeClass
	public static void startBrowser()throws Exception{
		driver = d.startUp();
	}
	@Test
	public void a_login_adminapp() throws Exception{
		System.out.println("Start Test: Login Admin Console");
		m.maximize_window(driver);
		in.admin(driver);
		System.out.println("End Test: Login Admin Console\n");
	}
	@Test
	public void b_display_transmittal_list_admin() throws Exception{
		System.out.println("Start Test: Goto Transmittal List");
		m.go_to_transmittal_admin(driver);
		m.go_to_create_transmittal(driver);
		System.out.println("End Test: Goto Transmittal List\n");
	}
	@Test
	public void c_search_transmittal_manual() throws Exception{
		System.out.println("Start Test: Search for SOA/CI Discharged Yesterday");
		transmittal_number = actl.search_and_generate_soa_ci(driver, "COCOLIFE HEALTH CARE", "6/13/2014");
		System.out.println("End Test: Search for SOA/CI Discharged Yesterday\n");
	}
	@Test
	public void d_verify_transmittal_table_headers() throws Exception{
		System.out.println("Start Test: Verify Transmittal Table Headers");
		actl.verify_transmittal_table_headers(driver,false);
		System.out.println("End Test: Verify Transmittal Table Headers\n");
	}
	@Test
	public void e_transmittal_table() throws Exception{
		System.out.println("Start Test: Create Visit Number Array");
		actl.create_and_verify_tables(driver, true);
		System.out.println("End Test: Create Visit Number Array\n");
	}
	@Test
	public void f_verify_transmittal_table_details() throws Exception{
		System.out.println("Start Test: Verify Transmittal Table Details");
		actl.search_verify_dynamic_table(driver, "draft");
		actl.verify_transmittal_table_count(driver, "cocolife");
		System.out.println("End Test: Verify Transmittal Table Details\n");
	}
	@Test
	public void g_proceed_to_draft_transmittal() throws Exception{
		System.out.println("Start Test: Proceed with Transmittal");
		actl.proceed_with_transmittal(driver, "cocolife", transmittal_number);
		System.out.println("End Test: Proceed with Transmittal\n");
	}
	@Test
	public void h_verify_transmittal_table_details() throws Exception{
		System.out.println("Start Test: Verify Draft Transmittal Details");
		m.verify_table_header_inpatient_hospital(driver);
		m.verify_table_header_outpatient_hospital(driver);
		m.verify_hmo_transmittal(driver,"cocolife", transmittal_number);
		actl.search_verify_dynamic_table(driver, "draft");
		actl.verify_transmittal_table_count(driver, "cocolife");
		m.verify_location_edit_transmittal(driver);
		System.out.println("End Test: Verify Draft Transmittal Details\n");
	}
	@Test
	public void i_compute_transmittal_details() throws Exception{
		System.out.println("Start Test: Compute Transmittal Amount");
		transmittal_amount = actl.compute_transmittal_table_headers_dynamic(driver, true);
		System.out.println("End Test: Compute Transmittal Amount\n");
	}
	@Test
	public void j_generate_transmittal() throws Exception{
		System.out.println("Start Test: Generate Transmittal");
		actl.click_generate_transmittal(driver, "4 patient", transmittal_number);
		System.out.println("End Test: Generate Transmittal\n");
	}
	@Test
	public void k_search_final_transmittal() throws Exception{
		System.out.println("Start Test: Search Final Transmittal");
		m.go_to_admin_home(driver);
		m.go_to_transmittal_admin(driver);
		m.check_transmittal_details(driver, transmittal_number, "COCOLIFE HEALTH CARE", transmittal_amount, true);
		atl.check_unopened_transmittal(driver);
		atl.search_transmittal_list(driver, transmittal_number, "final", "COCOLIFE HEALTH CARE");
		System.out.println("End Test: Search Final Transmittal\n");
	}
	@Test
	public void l_verify_transmittal_table_details() throws Exception{
		System.out.println("Start Test: Verify Final Transmittal Table Details");
		m.verify_location_edit_transmittal(driver);
		m.verify_hmo_transmittal_final(driver,"cocolife", transmittal_number);
		m.verify_final_transmittal_date(driver);
		actl.search_verify_dynamic_table(driver, "final");
		actl.verify_transmittal_table_count(driver, "cocolife");
		System.out.println("End Test: Verify Final Transmittal Table Details\n");
	}
	@Test
	public void m_preview_transmittal_memo() throws Exception{
		System.out.println("Start Test: Preview Transmittal Memo");
		atl.preview_transmittal_memo(driver);
		System.out.println("End Test: Preview Transmittal Memo\n");
	}
	@Test
	public void n_logout_app() throws Exception{
		System.out.println("Start Test: Logout Admin Console");
		out.admin(driver);
		System.out.println("End Test: Logout Admin Console\n");
	}
	@Test
	public void o_login_webapp() throws Exception{
		System.out.println("Start Test: Login Web Application Console");
		in.app(driver);
		System.out.println("End Test: Login Web Application Console\n");
	}
	@Test
	public void p_goto_transmittal_tab() throws Exception{
		System.out.println("Start Test: Goto Transmittal Tab");
		wat.goto_transmittal_tab(driver);
		System.out.println("End Test: Goto Transmittal Tab\n");
	}
	
	//PLEASE REMEMBER THAT SEARCH ON WEBAPP DATE TRANSMITTAL IS BASED ON TRANSMITTAL DATE NOT AVAILMENT DATE
	@Test
	public void q_search_in_webapp_transmittal_tab() throws Exception{
		System.out.println("Start Test: Search Transmittal in WebApp");
		String my_date = atl.date();
		System.out.println("Current Date: "+my_date);
		wat.input_transmittal_number(driver, transmittal_number);
		wat.manual_date_picker_webapp(driver, my_date, "start");
		wat.manual_date_picker_webapp(driver, my_date, "end");
		wat.select_location_of_transmittal(driver, "GC");
		wat.clear_search_transmittal(driver);
		wat.input_transmittal_number(driver, transmittal_number);
		
		//TODO
		//PLEASE CHANGE IT BACK TO TRANSMITTAL DATE
		wat.manual_date_picker_webapp(driver, my_date, "start");
		wat.manual_date_picker_webapp(driver, my_date, "end");
		//wat.manual_date_picker_webapp(driver, availment_date, "start");
		//wat.manual_date_picker_webapp(driver, availment_date, "end");
		
		
		wat.select_location_of_transmittal(driver, "GC");
		wat.search_it_transmittal(driver);
		wat.verify_search_results(driver);
		wat.new_transmittal_counter(driver);
		wat.new_text_beside_transmittal(driver);
		System.out.println("End Test: Search Transmittal in WebApp\n");
	}
	@Test
	public void r_compare_table_data_with_admin_transmittal() throws Exception{
		System.out.println("Start Test: Compare Transmittal in Table WebApp");
		String my_date = atl.date();
		my_date = wat.convert_date(my_date);
		String new_amount = String.valueOf(transmittal_amount);
		String new_ad = wat.convert_date(availment_date);
		wat.compare_data_to_search_output_via_table(driver, transmittal_number, new_ad, my_date, new_amount);
		System.out.println("End Test: Search Transmittal in Table WebApp\n");
	}
	//TODO
	//PLEASE ADD CODE TO MANIPULATE WINDOWS TO AND FROM SINCE NEW WINDOW IS SHOWN FOR TRANSMITTAL MEMO UPON CLICKING VIEW BUTTON 
	@Test
	public void s_view_webapp_transmittal() throws Exception{
		System.out.println("Start Test: View WebApp Transmittal");
		window_handle = driver.getWindowHandle();
		wat.view_transmittal_after_search(driver);
		Thread.sleep(5000);
		driver.switchTo().window(window_handle);
		System.out.println("End Test: View WebApp Transmittal\n");
	}
	@Test
	public void t_compare_sidebar_data_to_admin_transmittal() throws Exception{
		System.out.println("Start Test: Compare Transmittal in Sidebar WebApp");
		driver.switchTo().window(window_handle);
		wat.verify_transmittal_location(driver, "GC");
		wat.verify_transmittal_number(driver, transmittal_number);
		wat.verify_transmittal_date(driver, "current", "");
		wat.verify_availment_date(driver, availment_date);
		String new_amount = String.valueOf(transmittal_amount);
		wat.verify_transmittal_amount(driver, new_amount);
		System.out.println("End Test: Compare Transmittal in Sidebar WebApp\n");
	}
	@Test
	public void u_verify_visit_numbers_in_transmittal_webapp() throws Exception{
		System.out.println("Start Test: Compare Visit Numbers in Transmittal WebApp");
		wat.start_comparison_of_transmittals(driver, inVisitNo, outVisitNo);
		System.out.println("End Test: Compare Visit Numbers in Transmittal WebApp\n");
	}
	@Test
	public void v_verify_amounts_in_transmittal_webapp() throws Exception{
		System.out.println("Start Test: Compare Amounts in Transmittal WebApp");
		wat.start_comparison_of_transmittals_amount(driver, hb_inpatient_amount, hb_outpatient_amount, pf_inpatient_amount, pf_outpatient_amount);
		System.out.println("End Test: Compare Amounts in Transmittal WebApp\n");
	}
	@Test
	public void w_search_functionality_in_transmittal() throws Exception{
		System.out.println("Start Test: Search Data in Transmittal WebApp");
		wat.get_data_for_search_on_transmittal(driver, "SOA");
		wat.get_data_for_search_on_transmittal(driver, "CI");
		wat.get_data_for_search_on_transmittal(driver, "PIN");
		wat.get_data_for_search_on_transmittal(driver, "VISITNO");
		wat.get_data_for_search_on_transmittal(driver, "LNAME");
		System.out.println("End Test: Search Data in Transmittal WebApp\n");
	}
	@Test
	public void x_preview_transmittal_memo_in_webapp() throws Exception{
		System.out.println("Start Test: Preview Transmittal Memo in Transmittal WebApp");
		wat.click_preview_transmittal_memo_button(driver, true);
		driver.switchTo().window(window_handle);
		System.out.println("End Test: Preview Transmittal Memo in Transmittal WebApp\n");
	}
	@Test
	public void y_back_to_transmittal_search_page() throws Exception{
		System.out.println("Start Test: Back Function on Transmittal WebApp");
		wat.click_back_button(driver);
		System.out.println("End Test: Back Function on Transmittal WebApp\n");
	}
	@Test
	public void z_logout_transmittal_page() throws Exception{
		System.out.println("Start Test: Logout WebApp");
		out.app(driver);
		System.out.println("End Test: Logout WebApp\n");
	}
}
